package com.starrin.tennisfinder.extractors;

import com.starrin.tennisfinder.model.VenueAvailabilityDataHolder;
import com.starrin.tennisfinder.util.ExtractorUtil;

import java.util.HashSet;
import java.util.Set;
/**
 * Created by larsstarrin on 02/02/14.
 */

public class AvailabilityExtractorMyCourt {

    public static final String MYCOURT_PATTERN = ".*class=.*active.*court_id=\"(%s)\".*court_time=\"(?<hour>[0-9]{2})";

    public VenueAvailabilityDataHolder extractVenueAvailability(String response, String url, String indoorItems, String outdoorItems) {
        Set<Integer> availableHoursIndoors = new HashSet<>();
        if(indoorItems != null) {
            String patternStringIndoors =  String.format(MYCOURT_PATTERN, indoorItems);
            availableHoursIndoors = ExtractorUtil.getAvailableHours(patternStringIndoors, response);
        }

        Set<Integer> availableHoursOutdoors = new HashSet<>();
        if(outdoorItems != null) {
            String patternStringOutdoors =  String.format(MYCOURT_PATTERN, outdoorItems);
            availableHoursOutdoors = ExtractorUtil.getAvailableHours(patternStringOutdoors, response);
        }

        return ExtractorUtil.getVenueAvailabilityDataHolder(url, availableHoursIndoors, availableHoursOutdoors);
    }

}
